package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysDept;
import com.pine.dao.pineframework.mapper.SysDeptMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysDeptBo;
import com.pine.manager.pineframework.convertors.SysDeptConvertor;
import com.pine.manager.pineframework.query.SysDeptQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 部门表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysDeptManager extends BaseManager<SysDeptMapper, SysDept, Long, SysDeptBo, SysDeptQuery, SysDeptConvertor> {

    @Resource
    private SysDeptConvertor sysDeptConvertor;

    @Override
    public LambdaQueryWrapper<SysDept> encapsulateQueryWrapper(SysDeptQuery query) {
        LambdaQueryWrapper<SysDept> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysDept::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCode()), SysDept::getCode, query.getCode());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getParentId()), SysDept::getParentId, query.getParentId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getSort()), SysDept::getSort, query.getSort());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysDept::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysDept::getCreateUserId, query.getCreateUserId());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysDept::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysDept::getUpdateTime, query.getUpdateTimeEnd());

        // 排序
        queryWrapper.orderByAsc(SysDept::getSort);
        return queryWrapper;
    }
}
